<?php
namespace app\common\model;

class FavoriteModel extends BaseModel
{
    protected $name = 'favorite'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改

    /**
     * 加入收藏
     */
    public function addFavorite($uid, $channel, $infoId)
    {
        $map['uid']     = $uid;
        $map['channel'] = $channel;
        $map['info_id'] = $infoId;
        $info           = $this->where($map)->find();
        if ($info) {
            $this->error = '您已收藏过该信息！';
            return false;
        }
        $data = ['uid' => $uid, 'channel' => $channel, 'info_id' => $infoId, 'add_time' => time()];
        $this->addData($data);
        return true;
    }
}